package com.tian.user.controller;

import com.tian.authen.service.IUserService;
import com.tian.common.result.BaseResult;
import com.tian.common.result.Result;
import com.tian.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhumengping
 * @title: OAuth2ResourceController
 * @projectName zhump-cloud
 * @date 2023/8/4 11:29
 */
@RestController
@RequestMapping(value = "oauth2")
public class OAuth2ResourceController {

    @Autowired
    private IUserService userService;


    @PostMapping(value = "resource")
    @PreAuthorize("hasAuthority('USER')")
    public BaseResult<String[]> getResource(){
        String[] strings = {"resouce1", "resouce2", "resouce3"};
        return Result.ok(strings);
    }

    @PostMapping(value = "getUser")
    public BaseResult<User> getUser(@RequestBody RequestGetUser bean){
        userService.getUserByUser(bean.getToken());
        return Result.ok(userService.getUserByUser(bean.getToken()));


    }


    @PostMapping(value = "resource2")
    @PreAuthorize("hasAuthority('USER:ALL')")
    public BaseResult<String[]> resource2(){
        String[] strings = {"resouce4", "resouce5", "resouce6"};
        return Result.ok(strings);
    }
}
